<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%
        String url= request.getScheme()+"://"+request.getServerName()+":"
                +request.getServerPort()+request.getContextPath()+"/";
    %>
    <base href="<%=url%>">
    <%
        System.out.println(url);
    %>
    <%--    <script src="js/jquery-3.3.1.min.js"></script>--%>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <script src="js/jquery-3.3.1.min.js"></script>
</head>
<body>
<%--用户新增--%>
<form class="layui-form" action="" id="forms">
    <%--    required  lay-verify="required" 的作用就是做非空验证--%>
    <input type="hidden" name="id" value="${sUsers.id}">

    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" id="inp1" required  lay-verify="required" value="${sUsers.username}" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="text" id="inp2" name="password" required lay-verify="required" value="${sUsers.password}" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件修改</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <img style="width: 100px;height: 100px;border-radius: 50%" id="img" src="http://localhost:8080/upload/${sUsers.userimg}" >
    <input type="hidden" name="imgName" id="userimg" value="${sUsers.userimg}">


    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" lay-verify="required">
                <option value=""></option>
                <option value="1" ${sUsers.type eq 1?'selected':''}>普通用户</option>
                <option value="0" ${sUsers.type eq 0?'selected':''}>管理员</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">修改</button>
        </div>
    </div>

</form>
</body>
<script src="static/layui/layui.js"></script>
<script>
    layui.use('form',function () {
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;
        //监听提交
        form.on('submit(formDemo)',function (data) {
            $.post("user.do?method=updateOne",data.field,function (ss) {
                layer.msg(JSON.stringify(data.field))
                //调用父页面的load方法
                parent.load("user.do?method=findPage&current="+${msg1.current});
                //先得到当前iframe层的索引
                var index = parent.layer.getFrameIndex(window.name);  //window.name当前窗口的名字
                //通过父页面关闭当前页面
                parent.layer.close(index);
            },"json");
            return false; //false是取消提交，true是执行提交
        })
    })


    layui.use('upload', function(){
        var upload = layui.upload;
        var $ = layui.$;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: 'upload.do' //上传接口
            ,done: function(res){//上传完毕回调
                //图片回显
                $("#img").attr("src","http://localhost:8080/upload/"+res.data.src);
                //修改图片隐藏域值
                $("#userimg").val(res.data.src);
            }
            ,error: function(){
                //请求异常回调
                console.log("error")
            }
        });
    });

</script>
</html>

